﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

namespace Prism.Core.Storage
{
    public static class AdvancedPath
    {
        public static string GetRelativePath(string abusolutePath, string relativeRoot)
        {
            var relativePath = string.Empty;
            for (var i = 0; i < abusolutePath.Length; i++)
            {
                if (i >= relativeRoot.Length)
                {
                    relativePath += abusolutePath[i];
                }
            }

            return relativePath;
        }

        public static IEnumerable<string> EnumerateAllDirectories(string dir)
        {
            if (dir == null)
            {
                yield break;
            }
            else
            {
                var children = Directory.EnumerateDirectories(dir);
                foreach (var child_dir in children)
                {
                    var child_dir_children = Directory.EnumerateDirectories(child_dir);
                    if (child_dir_children.Count() == 0)
                    {
                        yield return child_dir;
                    }
                    else
                    {
                        foreach (var y in EnumerateAllDirectories(child_dir))
                        {
                            yield return y;
                        }
                    }
                }
            }
            yield return dir;
        }
    }
}
